package org.example.wikwok.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.example.wikwok.pojo.Like;
import org.springframework.stereotype.Repository;

@Repository
public interface LikeMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Like record);

    int insertSelective(Like record);

    Like selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Like record);

    int updateByPrimaryKey(Like record);

    @Select("""
            SELECT COUNT(l.id) AS total_likes
            FROM Video v
                     LEFT JOIN `Like` l ON v.id = l.videoId
            WHERE v.uploaderId = #{userId};""")
    int selectUserLikeCount(Integer userId);

    @Select("SELECT COUNT(id) FROM `Like` WHERE videoId = #{videoId}")
    int selectCountByVideoId(int videoId);
    @Delete("DELETE FROM `Like` WHERE videoId = #{videoId}")
    void deleteByVideoId(int videoId);


    void deleteByVideoIdAndUserId(int videoid, int userid);

}